from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-11-26 14:03:37.691775
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 26, Nov, 2021
Time: 14:03:42
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.2346
Nobs: 487.000 HQIC: -47.7045
Log likelihood: 5560.88 FPE: 1.41305e-21
AIC: -48.0086 Det(Omega_mle): 1.17683e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.389033 0.084163 4.622 0.000
L1.Burgenland 0.094322 0.044820 2.104 0.035
L1.Kärnten -0.116088 0.022965 -5.055 0.000
L1.Niederösterreich 0.160166 0.093287 1.717 0.086
L1.Oberösterreich 0.122207 0.094762 1.290 0.197
L1.Salzburg 0.282030 0.048050 5.870 0.000
L1.Steiermark 0.019909 0.062275 0.320 0.749
L1.Tirol 0.108242 0.050077 2.162 0.031
L1.Vorarlberg -0.084271 0.044127 -1.910 0.056
L1.Wien 0.031854 0.084360 0.378 0.706
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.019418 0.187100 0.104 0.917
L1.Burgenland -0.051184 0.099638 -0.514 0.607
L1.Kärnten 0.036296 0.051053 0.711 0.477
L1.Niederösterreich -0.211775 0.207382 -1.021 0.307
L1.Oberösterreich 0.477373 0.210661 2.266 0.023
L1.Salzburg 0.310750 0.106817 2.909 0.004
L1.Steiermark 0.096035 0.138441 0.694 0.488
L1.Tirol 0.308244 0.111324 2.769 0.006
L1.Vorarlberg 0.007799 0.098096 0.080 0.937
L1.Wien 0.017697 0.187537 0.094 0.925
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.240942 0.042669 5.647 0.000
L1.Burgenland 0.093000 0.022723 4.093 0.000
L1.Kärnten -0.004102 0.011643 -0.352 0.725
L1.Niederösterreich 0.216880 0.047295 4.586 0.000
L1.Oberösterreich 0.158925 0.048043 3.308 0.001
L1.Salzburg 0.034288 0.024360 1.408 0.159
L1.Steiermark 0.028092 0.031572 0.890 0.374
L1.Tirol 0.074904 0.025388 2.950 0.003
L1.Vorarlberg 0.057119 0.022372 2.553 0.011
L1.Wien 0.102137 0.042769 2.388 0.017
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181304 0.041476 4.371 0.000
L1.Burgenland 0.042612 0.022088 1.929 0.054
L1.Kärnten -0.011873 0.011317 -1.049 0.294
L1.Niederösterreich 0.143683 0.045973 3.125 0.002
L1.Oberösterreich 0.336927 0.046699 7.215 0.000
L1.Salzburg 0.097850 0.023679 4.132 0.000
L1.Steiermark 0.111474 0.030690 3.632 0.000
L1.Tirol 0.084706 0.024678 3.432 0.001
L1.Vorarlberg 0.055070 0.021746 2.532 0.011
L1.Wien -0.041346 0.041573 -0.995 0.320
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184924 0.080412 2.300 0.021
L1.Burgenland -0.042564 0.042823 -0.994 0.320
L1.Kärnten -0.035914 0.021942 -1.637 0.102
L1.Niederösterreich 0.121771 0.089130 1.366 0.172
L1.Oberösterreich 0.174656 0.090539 1.929 0.054
L1.Salzburg 0.252725 0.045908 5.505 0.000
L1.Steiermark 0.076437 0.059500 1.285 0.199
L1.Tirol 0.130352 0.047845 2.724 0.006
L1.Vorarlberg 0.107910 0.042160 2.560 0.010
L1.Wien 0.034032 0.080600 0.422 0.673
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.071662 0.063614 1.127 0.260
L1.Burgenland 0.016406 0.033877 0.484 0.628
L1.Kärnten 0.050928 0.017358 2.934 0.003
L1.Niederösterreich 0.182942 0.070510 2.595 0.009
L1.Oberösterreich 0.343219 0.071625 4.792 0.000
L1.Salzburg 0.050044 0.036318 1.378 0.168
L1.Steiermark -0.009572 0.047070 -0.203 0.839
L1.Tirol 0.123651 0.037850 3.267 0.001
L1.Vorarlberg 0.057477 0.033353 1.723 0.085
L1.Wien 0.114588 0.063762 1.797 0.072
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186597 0.077398 2.411 0.016
L1.Burgenland 0.011284 0.041217 0.274 0.784
L1.Kärnten -0.060103 0.021119 -2.846 0.004
L1.Niederösterreich -0.117403 0.085788 -1.369 0.171
L1.Oberösterreich 0.220119 0.087145 2.526 0.012
L1.Salzburg 0.036344 0.044187 0.823 0.411
L1.Steiermark 0.268682 0.057269 4.692 0.000
L1.Tirol 0.488930 0.046052 10.617 0.000
L1.Vorarlberg 0.073715 0.040580 1.817 0.069
L1.Wien -0.104582 0.077579 -1.348 0.178
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.136403 0.085653 1.593 0.111
L1.Burgenland -0.013130 0.045614 -0.288 0.773
L1.Kärnten 0.064039 0.023372 2.740 0.006
L1.Niederösterreich 0.173966 0.094939 1.832 0.067
L1.Oberösterreich -0.075367 0.096440 -0.781 0.435
L1.Salzburg 0.222136 0.048900 4.543 0.000
L1.Steiermark 0.134286 0.063378 2.119 0.034
L1.Tirol 0.051176 0.050964 1.004 0.315
L1.Vorarlberg 0.142548 0.044908 3.174 0.002
L1.Wien 0.167588 0.085853 1.952 0.051
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465488 0.047230 9.856 0.000
L1.Burgenland -0.001754 0.025152 -0.070 0.944
L1.Kärnten -0.012998 0.012887 -1.009 0.313
L1.Niederösterreich 0.176349 0.052350 3.369 0.001
L1.Oberösterreich 0.262409 0.053178 4.935 0.000
L1.Salzburg 0.018099 0.026964 0.671 0.502
L1.Steiermark -0.012267 0.034947 -0.351 0.726
L1.Tirol 0.069156 0.028102 2.461 0.014
L1.Vorarlberg 0.057044 0.024763 2.304 0.021
L1.Wien -0.019319 0.047340 -0.408 0.683
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.025960 0.089905 0.153392 0.136554 0.065643 0.080953 0.015347 0.207481
Kärnten 0.025960 1.000000 -0.037212 0.128778 0.047273 0.071464 0.457390 -0.082741 0.094556
Niederösterreich 0.089905 -0.037212 1.000000 0.273357 0.094487 0.256609 0.043679 0.142575 0.241371
Oberösterreich 0.153392 0.128778 0.273357 1.000000 0.186044 0.289634 0.159627 0.126800 0.171531
Salzburg 0.136554 0.047273 0.094487 0.186044 1.000000 0.121863 0.057827 0.109732 0.059738
Steiermark 0.065643 0.071464 0.256609 0.289634 0.121863 1.000000 0.133307 0.086989 0.006045
Tirol 0.080953 0.457390 0.043679 0.159627 0.057827 0.133307 1.000000 0.062264 0.128451
Vorarlberg 0.015347 -0.082741 0.142575 0.126800 0.109732 0.086989 0.062264 1.000000 -0.011039
Wien 0.207481 0.094556 0.241371 0.171531 0.059738 0.006045 0.128451 -0.011039 1.000000